<?php

namespace App\Admin\Actions\Show;

use Dcat\Admin\Actions\Response;
use Dcat\Admin\Show\AbstractTool;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use App\Jobs\PushClueToLMS;
use App\Models\CustomerInfo;

class PushLms extends AbstractTool
{
    /**
     * @return string
     */
    protected $title = '重新推送';

    /**
     * Handle the action request.
     *
     * @param Request $request
     *
     * @return Response
     */
    public function handle(Request $request)
    {
        $customerInfo = CustomerInfo::findOrFail($this->getKey());
        //异步推送给LMS
        dispatch(new PushClueToLMS($customerInfo));
        return $this->response()
            ->success('已添加到队列任务');
    }

    /**
     * @return string|void
     */
    protected function href()
    {
        // return admin_url('auth/users');
    }

    /**
     * @return string|array|void
     */
    public function confirm()
    {
        return ['重新推送?'];
    }

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }

    /**
     * @return array
     */
    protected function parameters()
    {
        return [];
    }

    // 如果你想自定义动作按钮的HTML，可以重写此方法
    protected function html()
    {
        $data = '<div class="btn-group pull-right btn-mini" style="margin-right: 5px">' . parent::html() . '</div>';
        return <<<HTML
        {$data}
        HTML;
    }
}
